package com.canyou.common;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author cd
 */
@Api(tags = "websocket")
@RequestMapping(value = "/websocket")
@Slf4j
@RestController
public class WebSocketController {

    @Autowired
    private WebSocket webSocket;

    @ApiOperation(value = "websocket群体发送")
    @GetMapping(value = "/sendAllWebSocket")
    public void sendAllMessage() {
        webSocket.sendAllMessage("websocket群体发送！");
    }

    @ApiOperation(value = "websocket当前登录用户发送")
    @GetMapping(value = "/sendOneWebSocket")
    public void sendOneWebSocket(@RequestParam(required = false) String userName) {
        webSocket.sendOneMessage(userName, "websocket当前登录用户发送！");
    }
}
